﻿using System;
using System.Collections.Generic;
using System.IO;

using System.Linq;
using System.Net.Configuration;

namespace BulkUploadGovernanceFiles
{
    public class DiskFilesManagement
    {
        private readonly string _governanceFilesFolder;

        public DiskFilesManagement()
        {
            _governanceFilesFolder = ConfigManagement.FilePath;
        }

        public Stream ReadFile(string fileName)
        {
            var filePath = Path.Combine(_governanceFilesFolder, fileName);
            return new FileStream(filePath, FileMode.Open);
        }

        public FileInfo[] GetFilesInFolder()
        {
            DirectoryInfo d = new DirectoryInfo(_governanceFilesFolder);
            if (d.Exists)
            {
                return d.GetFiles("*.pdf");    
            }
            return null;
            
        }
        
        public void GetFileStream(string diskFileName, Action<FileStream> useFileStream)
        {
            using (var fileStream = new FileStream(diskFileName, FileMode.Open))
            {
                useFileStream(fileStream);
            }
        }
        public void DeleteFile(FileInfo file)
        {
            File.Delete(file.FullName);
        }
    }
}
